﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DoAnOOP.DataAccessLayer;
using DevComponents.DotNetBar;

namespace DoAnOOP
{
    public partial class frmLoginServer : Office2007Form
    {


        public frmLoginServer()
        {
            InitializeComponent();
        }

        private clsConnect _connect = new clsConnect();
        private bool _isConnected = false;

        private void frmLoginServer_Load(object sender, EventArgs e)
        {
            comboBox2.Text = "Windows Authentication";

            _connect.ReadSource();
            comboBox1.Text = _connect.Server.Trim();
            textBox1.Text = _connect.Database.Trim();
            textBox2.Text = _connect.User.Trim();
            textBox3.Text = _connect.Password.Trim();
        }
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox2.SelectedIndex == 0)
                textBox3.Enabled = textBox2.Enabled = false;
            else
                textBox3.Enabled = textBox2.Enabled = true;
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            _connect.WriterFile(comboBox1.Text, textBox1.Text, textBox2.Text, textBox3.Text);
            try
            {
                _connect.ReadSource();
                _connect.Connect();
                _isConnected = true;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK);
                _isConnected = false;
            }

            if (_isConnected)
                this.Close();
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {

        }

    }
}
